package cn.stylefeng.guns.modular.web.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.modular.web.entity.Gold;
import cn.stylefeng.guns.modular.web.mapper.GoldMapper;
import cn.stylefeng.guns.modular.web.service.IGoldService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 描述：365天打卡金币奖励设置表 service业务层
 * 作者：chenhuiyan
 * 时间：2020-04-18
 */
@Service
@Transactional(readOnly = true)
public class GoldServiceImpl extends ServiceImpl<GoldMapper, Gold> implements IGoldService {

    /**
     * 查询列表
     * @param params
     * @return
     */
    public Page<Map<String, Object>> list(Map<String, Object> params) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.list(page, params);
    }

    /**
     * 生成365天金币
     * @param goldNum
     */
    @Transactional
    public void goldNumDay(Integer goldNum){
        List<Gold> goldList = new ArrayList<>();
        for(int i = 1; i <= 365; i++){
            Gold gold = new Gold();
            gold.preInsert();
            gold.setGoldNum(goldNum);
            gold.setDayNum(i);
            goldList.add(gold);
        }
        this.remove(new QueryWrapper<Gold>()); //清空表
        this.saveBatch(goldList); //保存
    }

}
